package cn.s1995.sloth.bizs.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;

import cn.s1995.sloth.bizs.entity.Prod;
import cn.s1995.sloth.bizs.entity.VideoProdRecommend;
import cn.s1995.sloth.bizs.mapper.VideoProdRecommendMapper;
import cn.s1995.sloth.bizs.oo.vo.VideoProdRecommendVO;
import cn.s1995.sloth.bizs.service.VideoProdRecommendService;

/**
 * 视频产品推荐
 *
 * @author Sasshi
 * @date 2023-12-12 15:25:29
 */
@Service
public class VideoProdRecommendServiceImpl extends ServiceImpl<VideoProdRecommendMapper, VideoProdRecommend> implements VideoProdRecommendService {

	@Override
	public void removeByVideoId(Long videoId) {
		LambdaQueryWrapper<VideoProdRecommend> lambdaQuery = Wrappers.lambdaQuery();
		lambdaQuery.eq(VideoProdRecommend::getVideoId, videoId);
		this.remove(lambdaQuery);
	}

	@Override
	public List<VideoProdRecommendVO> getByVideoId(Long videoId) {
		MPJLambdaWrapper<VideoProdRecommend> wrapper = new MPJLambdaWrapper<VideoProdRecommend>()
																.selectAll(VideoProdRecommend.class)
																.selectAssociation(Prod.class, VideoProdRecommendVO::getProd)
//																.selectAs(Prod::getName, VideoProdRecommendVO::getProdName)
//																.selectAs(Prod::getAmount, VideoProdRecommendVO::getProdAmount)
//																.selectAs(Prod::getThumbnail, VideoProdRecommendVO::getProdThumbnail)
//																.selectAs(Prod::getIsSale, VideoProdRecommendVO::getProdIsSale)
																.leftJoin(Prod.class, Prod::getId, VideoProdRecommend::getProdId)
																.eq(VideoProdRecommend::getVideoId, videoId);
		return baseMapper.selectJoinList(VideoProdRecommendVO.class, wrapper);
	}
}
